*******************************************************************************
*****************************  FIGURE A2  *************************************
*******  Women's Influence and Authority by Group Gender Composition **********
*******************************************************************************


clear all
set more off

//cd "C:/Users/ganth/Dropbox/StrengthInNumbersReplicationPackage/replicable/figure_a2"

********************************************************************************

***********Figure A2a**************

**Study 1 Analysis

foreach var in genderminfl_labavg_ratio genderlinfl_labavg_ratio {
    use "figure_a2_dataset_1.dta", clear
	reg `var' b3.fall_condition, robust
	margins fall_condition, post
	estimates store margins
	test _b[1bn.fall_condition] = _b[3.fall_condition]
	outreg2 margins using "intermediate_data/study1_group`var'.dta", replace dta side noparen noas

	ttest `var', by(fall_condition)
	putexcel set "intermediate_data/study1_group`var'_1p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = (1.15)
	*putexcel save

	use "intermediate_data/study1_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1bn.fall_condition"
	replace v1="Majority Female" if v1=="3.fall_condition"
	gen ci=v3*1.96
	export delimited "intermediate_data/study1_group`var'_forgraphing.csv", replace
}

**Study 2 Analysis

foreach var in genderminfl_ratio_r1 genderlinfl_ratio_r1 {
    use "figure_a2_dataset_2.dta", clear
	reg `var' i.condition_2f, robust
	margins condition_2f, post
	estimates store margins
	test _b[1.condition_2f] = _b[0.condition_2f]
	outreg2 margins using "intermediate_data/study2_group`var'.dta", replace dta side noparen noas

	ttest `var' if condition_2f==0 | condition_2f==1, by(condition_2f)
	putexcel set "intermediate_data/study2_group`var'_1p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = (1.15)
	*putexcel save

	use "intermediate_data/study2_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1.condition_2f"
	replace v1="Majority Female" if v1=="0bn.condition_2f"
	gen ci=v3*1.96
	export delimited "intermediate_data/study2_group`var'_forgraphing.csv", replace
}

**Combined Analysis
	
foreach var in genderminfl_ratio_ravg genderlinfl_ratio_ravg {
    use "figure_a2_dataset_3.dta", clear
	reg `var' i.condition_2f, robust
	margins condition_2f, post
	estimates store margins
	test _b[1.condition_2f] = _b[0.condition_2f]
	outreg2 margins using "intermediate_data/combined_group`var'.dta", replace dta side noparen noas

	ttest `var' if condition_2f==0 | condition_2f==1, by(condition_2f)
	putexcel set "intermediate_data/combined_group`var'_1p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = (1.15)
	*putexcel save

	use "intermediate_data/combined_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1.condition_2f"
	replace v1="Majority Female" if v1=="0bn.condition_2f"
	gen ci=v3*1.96
	export delimited "intermediate_data/combined_group`var'_forgraphing.csv", replace
	drop ci
	rename (v1 v2 v3) (condition val se)
	ssc install texsave
	texsave * using "intermediate_data/figure_a2_data_`var'.tex", replace
}

clear

*******Figure A2b*************

**Study 1 Analysis
foreach var in genderminfl_f2avg_ratio genderlinfl_f2avg_ratio {
	use "figure_a2_dataset_1.dta", clear
	reg `var' b3.fall_condition, robust
	margins fall_condition, post
	estimates store margins
	test _b[1bn.fall_condition] = _b[3.fall_condition]
	outreg2 margins using "intermediate_data/study1_group`var'", replace dta side noparen noas

	ttest `var', by(fall_condition)
	putexcel set "intermediate_data/study1_group`var'_4p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = 1.75

	use "intermediate_data/study1_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1bn.fall_condition"
	replace v1="Majority Female" if v1=="3.fall_condition"
	gen ci=v3*1.96
	export delimited "intermediate_data/study1_group`var'_forgraphing.csv", replace
}


**Study 2 Analysis
foreach var in femvotesminfl_avgpre_ratio femvoteslinfl_avgpre_ratio {
use "figure_a2_dataset_2.dta", clear
	drop if genderminfl_ratio_r1 == .
	reg `var' i.condition_2f, robust
	margins condition_2f, post
	estimates store margins
	test _b[1.condition_2f] = _b[0.condition_2f]
	outreg2 margins using "intermediate_data/study2_group`var'", replace dta side noparen noas

	ttest `var' if condition_2f==0 | condition_2f==1, by(condition_2f)
	putexcel set "intermediate_data/study2_group`var'_4p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = (r(mu_1)+(r(sd)))

	use "intermediate_data/study2_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1.condition_2f"
	replace v1="Majority Female" if v1=="0bn.condition_2f"
	gen ci=v3*1.96
	export delimited "intermediate_data/study2_group`var'_forgraphing.csv", replace
}


**Combined Analysis
foreach var in femvotesminfl_avgpre_ratio femvoteslinfl_avgpre_ratio {
	use "figure_a2_dataset_3.dta", clear
	drop if genderminfl_ratio_ravg == .
	reg `var' i.condition_2f, robust
	margins condition_2f, post
	estimates store margins
	test _b[1.condition_2f] = _b[0.condition_2f]
	outreg2 margins using "intermediate_data/combined_group`var'", replace dta side noparen noas

	ttest `var' if condition_2f==0 | condition_2f==1, by(condition_2f)
	putexcel set "intermediate_data/combined_group`var'_4p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = (r(mu_1)+(r(sd)))

	use "intermediate_data/combined_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1.condition_2f"
	replace v1="Majority Female" if v1=="0bn.condition_2f"
	gen ci=v3*1.96
	export delimited "intermediate_data/combined_group`var'_forgraphing.csv", replace
}

clear

***********Figure A2c************

**Study 1 Analysis
foreach var in gendermsupp_labavg_ratio {
	use "figure_a2_dataset_1.dta", clear
	reg `var' b3.fall_condition, robust
	margins fall_condition, post
	estimates store margins
	test _b[1bn.fall_condition] = _b[3.fall_condition]
	outreg2 margins using "intermediate_data/study1_group`var'.dta", replace dta side noparen noas

	ttest `var', by(fall_condition)
	putexcel set "intermediate_data/study1_group`var'_1p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = (1.5)

	use "intermediate_data/study1_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1bn.fall_condition"
	replace v1="Majority Female" if v1=="3.fall_condition"
	gen ci=v3*1.96
	export delimited "intermediate_data/study1_group`var'_forgraphing.csv", replace
}

**Study 2 Analysis
foreach var in gendermsupp_ravg_ratio {
	use "figure_a2_dataset_2.dta", clear
	reg `var' i.condition_2f, robust
	margins condition_2f, post
	estimates store margins
	test _b[1.condition_2f] = _b[0.condition_2f]
	outreg2 margins using "intermediate_data/study2_group`var'.dta", replace dta side noparen noas

	ttest `var' if condition_2f==0 | condition_2f==1, by(condition_2f)
	putexcel set "intermediate_data/study2_group`var'_1p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = (1.5)

	use "intermediate_data/study2_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1.condition_2f"
	replace v1="Majority Female" if v1=="0bn.condition_2f"
	gen ci=v3*1.96
	export delimited "intermediate_data/study2_group`var'_forgraphing.csv", replace
}

**Combined Analysis
foreach var in gendermsupp_ravg_ratio {
	use "figure_a2_dataset_3.dta", clear
	reg `var' i.condition_2f, robust
	margins condition_2f, post
	estimates store margins
	test _b[1.condition_2f] = _b[0.condition_2f]
	outreg2 margins using "intermediate_data/combined_group`var'.dta", replace dta side noparen noas

	ttest `var' if condition_2f==0 | condition_2f==1, by(condition_2f)
	putexcel set "intermediate_data/combined_group`var'_1p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = (1.5)

	use "intermediate_data/combined_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1.condition_2f"
	replace v1="Majority Female" if v1=="0bn.condition_2f"
	gen ci=v3*1.96
	export delimited "intermediate_data/combined_group`var'_forgraphing.csv", replace
	drop ci
	rename (v1 v2 v3) (condition val se)
	ssc install texsave
	texsave * using "intermediate_data/jpe_figure_1_table_`var'.tex", replace
}

clear
